const sq = require("../../db/mysql");
const User = sq.model('user');
const UserInfo = sq.model('user_info');
module.exports = {
    async login(name, pw) {//登录
      try {
        let data = await User.findOne({where:{username: name, password: pw}});  
        return {code: 200, data: data.dataValues};
      } catch (error) {
        console.log(error);
        return {code: 400, msg: '查找出错'}
      }
    },
    async register(name, pw) {//注册
      try {
        let time = Math.floor(new Date().getTime() / 1000);
        let data = await User.create({username: name, password: pw, create_at: time, update_at: time});
        return {code: 200, data:{}};
      } catch (error) {
        console.log(error);
        return {code: 400, msg: '查找出错'}
      }
    },
    async getInfo(uid) {//获取用户信息
      try {
        let data = await UserInfo.findOne({where:{uid: uid}});
        return {code: 200, data: data.dataValues}
      } catch (error) {
        console.log(error);
        return {code: 400, msg: '查找出错'}
      }
    }
}